40A - Find Color - CodeForces Solution


constructive algorithms geometry implementation math *1300

Please click on ads to support us..

Python Code:

n,m=[int(i)for i in input().split(' ')]
x=((n*n+m*m)**0.5%2-1)*m*n
print('white') if x>0 and x!=-m*n else print('black')

C++ Code:

#include<bits/stdc++.h>

using namespace std;

#define endl "\n"
typedef long long ll;
const int N = 2005;
int a[N];

inline void f() {
    int x, y;
    cin >> x >> y;
    if (x * y == 0) {
        cout << "black" << endl;
        return;
    }
    int len_2 = x * x + y * y;
    for (int i = 1; i <= 2000; i++) {
        a[i] = i * i;
        if (a[i] == len_2) {
            cout << "black" << endl;
            return;
        }
        if (x * y > 0) {
            if (len_2 > i * i && len_2 < (i + 1) * (i + 1)) {
                if (i & 1) cout << "white" << endl;
                else cout << "black" << endl;
            }
        } else {
            if (len_2 > i * i && len_2 < (i + 1) * (i + 1)) {
                if (i & 1) cout << "black" << endl;
                else cout << "white" << endl;
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    f();
    return 0;
}


Comments

Submit
0 Comments
More Questions

1047B - Cover Points
1381B - Unmerge
1256A - Payment Without Change
908B - New Year and Buggy Bot
979A - Pizza Pizza Pizza
731A - Night at the Museum
742A - Arpa’s hard exam and Mehrdad’s naive cheat
1492A - Three swimmers
1360E - Polygon
1517D - Explorer Space
1230B - Ania and Minimizing
1201A - Important Exam
676A - Nicholas and Permutation
431A - Black Square
474B - Worms
987B - High School Become Human
1223A - CME
1658B - Marin and Anti-coprime Permutation
14B - Young Photographer
143A - Help Vasilisa the Wise 2
320A - Magic Numbers
1658A - Marin and Photoshoot
514A - Chewbaсca and Number
382A - Ksenia and Pan Scales
734B - Anton and Digits
1080A - Petya and Origami
1642D - Repetitions Decoding
1440A - Buy the String
1658F - Juju and Binary String
478A - Initial Bet